package com.hiultra.archive.controller;

import com.hiultra.archive.domain.ArcCheck;
import com.hiultra.archive.service.IArcCheckService;
import com.hiultra.common.annotation.Log;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.core.page.TableDataInfo;
import com.hiultra.common.enums.BusinessType;
import com.hiultra.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 盘点Controller
 *
 * @author ls
 * @date 2023-09-05
 */
@Api(tags = "盘点Controller")
@RestController
@RequestMapping("/archive/check")
public class ArcCheckController extends BaseController {
    @Autowired
    private IArcCheckService arcCheckService;

    /**
     * 查询盘点列表
     */
    @ApiOperation(value = "查询盘点列表", notes = "查询盘点列表")
    @PreAuthorize("@ss.hasPermi('archive:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArcCheck arcCheck) {
        startPage();
        List<ArcCheck> list = arcCheckService.selectArcCheckList(arcCheck);
        return getDataTable(list);
    }

    /**
     * 导出盘点列表
     */
    @ApiOperation(value = "导出盘点列表", notes = "导出盘点列表")
    @PreAuthorize("@ss.hasPermi('archive:check:export')")
    @Log(title = "盘点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArcCheck arcCheck) {
        List<ArcCheck> list = arcCheckService.selectArcCheckList(arcCheck);
        ExcelUtil<ArcCheck> util = new ExcelUtil<ArcCheck>(ArcCheck.class);
        util.exportExcel(response, list, "盘点数据");
    }

    /**
     * 获取盘点详细信息
     */
    @ApiOperation(value = "获取盘点详细信息", notes = "获取盘点详细信息")
    @PreAuthorize("@ss.hasPermi('archive:check:query')")
    @GetMapping(value = "/{checkId}")
    public AjaxResult getInfo(@PathVariable("checkId") Long checkId) {
        return AjaxResult.success(arcCheckService.selectArcCheckByCheckId(checkId));
    }

    /**
     * 新增盘点
     */
    @ApiOperation(value = "新增盘点", notes = "新增盘点")
    @PreAuthorize("@ss.hasPermi('archive:check:add')")
    @Log(title = "盘点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArcCheck arcCheck) {
        arcCheck.setCreateBy(getUsername());
        return toAjax(arcCheckService.insertArcCheck(arcCheck));
    }

    /**
     * 修改盘点
     */
    @ApiOperation(value = "修改盘点", notes = "修改盘点")
    @PreAuthorize("@ss.hasPermi('archive:check:edit')")
    @Log(title = "盘点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArcCheck arcCheck) {
        arcCheck.setUpdateBy(getUsername());
        return toAjax(arcCheckService.updateArcCheck(arcCheck));
    }

    /**
     * 删除盘点
     */
    @ApiOperation(value = "删除盘点", notes = "删除盘点")
    @PreAuthorize("@ss.hasPermi('archive:check:remove')")
    @Log(title = "盘点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{checkIds}")
    public AjaxResult remove(@PathVariable Long[] checkIds) {
        return toAjax(arcCheckService.deleteArcCheckByCheckIds(checkIds));
    }
}
